<template>
	<view class="home-page">
		<view class="title">
			闪购商城
		</view>
		<view class="content">
			<view class="top-box">
				<view class="use">
					<view class="use-item" v-for="(item,index) in useList" @click="golist(index)" :key="index">
						<image :src="item.img" mode=""></image>
						<view class="use-text">
							{{item.text}}
						</view>
					</view>
				</view>
				<view class="tabs">
					<view :class="current == index?'active-item': 'tabs-item'" class="tabs-item"
						v-for="(item,index) in tabsList" :key="index" @click="cutTab(index,item.id)">
						{{item.name}}
					</view>
				</view>
				<image class="home-bg3" src="../../static/home/home-bg3.png" mode=""></image>
			</view>

			<view v-if="list.length > 0" style="padding-bottom: 100rpx;">
				<view class="goods">
					<view class="goods-item" v-for="(item,index) in list" :key="index" @click="goDetails(item.id)">
						<image :src="item.logo" mode=""></image>
						<view class="goods-bottom">
							<view class="goods-title">
								{{item.goods_name}}
							</view>
							<view class="tisp">
								<text class="text1">包邮到家</text><text class="text2">·</text><text class="text3">爆品推荐</text>
							</view>
							<view class="goods-info">
								<view class="goods-price">
									￥{{item.price}}
								</view>
								<view class="cart">
									<image src="/static/home/home-icon2.png" mode=""></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" margin-top="20" />
			</view>
			<u-empty v-else mode="car" icon="../../static/home/none.png" text="暂无数据" marginTop="50">
			</u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabsList: [],
				current: 0,
				list: [],
				show: false,
				page: 1,
				id: '',
				useList: [{
						img: '../../static/home/icon1.png',
						text: '全部订单'
					},
					{
						img: '../../static/home/icon2.png',
						text: '待发货'
					},
					{
						img: '../../static/home/icon3.png',
						text: '待收货'
					},
					{
						img: '../../static/home/icon4.png',
						text: '已收货'
					},
					{
						img: '../../static/home/icon5.png',
						text: '收货地址'
					}
				],
				status: 'loadmore',
			}
		},
		onLoad() {
			this.posttabs()
		},
		onReachBottom() {
			this.page++
			this.status = 'loading';
			this.getList()
		},
		methods: {
			golist(e) {
				if (e == 4) {
					uni.navigateTo({
						url: '/pages/shop/address/index'
					})
				} else {
					uni.navigateTo({
						url: '/pages/shop/orderlist/index?cutt=' + e
					})
				}

			},
			posttabs() {
				this.$Request({
					method: 'POST',
					url: '/api/Shop/cateList',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.tabsList = res.data
						this.id = this.tabsList[0].id
						this.getList()
					}
				})
			},
			getList() {
				let params = {
					c_id: this.id,
					page: this.page
				}
				this.$Request({
					method: 'POST',
					url: '/api/Shop/goodsList',
					data: params,
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						if (res.data.list.length < 10) {
							this.status = 'nomore';
						}
						if (this.page == 1) {
							this.list = res.data.list
						} else {
							this.list = [...this.list, ...res.data.list]
						}
					}
				})
			},
			cutTab(index, id) {
				this.current = index
				this.id = id
				this.page = 1
				this.getList()
			},
			goDetails(id) {
				uni.navigateTo({
					url: '/pages/shop/details/index?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home-page {
		background-image: url('../../static/home/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 500rpx;
		min-height: 80vh;
		padding: 30rpx;
		position: relative;

		.title {
			color: #000000;
			font-size: 42rpx;
			font-weight: bold;
		}

		.nav-title {
			color: #000000;
		}

		.content {
			width: 100%;
			position: absolute;
			left: 0;
			right: 0;
			padding: 30rpx;
			margin-top: 20rpx;
			.top-box {
				background: linear-gradient(180deg, rgba(255, 255, 255, 0.7) 7.45%, #FFFFFF 58.5%);
				border: 1px solid #FFFFFF;
				padding: 20rpx;
				border-radius: 16px;
				border-width: 1px;
				position: relative;
				.home-bg3{
					position: absolute;
					right: -20rpx;
					top: -70px;
					width: 120px;
					height: 120px;
					z-index: -1;
				}
				.use {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 20rpx;

					.use-item {
						text-align: center;

						image {
							width: 60rpx;
							height: 60rpx;
						}

						.use-text {
							font-weight: 400;
							font-size: 12px;
							color: #4B4B4B;
						}
					}
				}


				.tabs {
					display: flex;
					align-items: center;
					justify-content: space-between;
					background-color: #F5F6F9;
					border-radius: 20rpx;
					padding: 15rpx;
					.tabs-item {
						width: 24%;
						font-size: 26rpx;
						font-weight: 500;
						color: #8F8F8F;
						text-align: center;
						padding: 15rpx 0;
					}

					.active-item {
						background-color: #FFFFFF;
						border-radius: 10rpx;
						color: #000000;
					}
				}
			}


			.goods {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
				margin-top: 10rpx;

				.goods-item {
					width: 48%;
					margin-top: 30rpx;
					box-shadow: 0rpx 3rpx 32rpx 1rpx rgba(0, 0, 0, 0.08);
					border-radius: 30rpx;

					image {
						width: 100%;
						height: 320rpx;
						border-top-right-radius: 30rpx;
						border-top-left-radius: 30rpx;
					}

					.goods-bottom {
						padding: 20rpx;
						background-color: #fff;
						border-bottom-left-radius: 30rpx;
						border-bottom-right-radius: 30rpx;

						.goods-title {
							font-size: 26rpx;
							color: #000000;
							font-weight: 600;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}
						.tisp{
							color: #A26D47;
							font-size: 26rpx;
							margin-top: 10rpx;
							.text1{
								color: #A26D47;
							}
							.text2{
								color: #999;
								font-weight: 900;
								padding: 0 5rpx;
							}
							.text3{
								color: #FF2538;
							}
						}
						.goods-info {
							display: flex;
							justify-content: space-between;
							margin-top: 10rpx;

							.goods-price {
								font-size: 28rpx;
								color: #FF4E4E;
								font-weight: bold;

								text {
									font-weight: normal;
									color: #cccccc;
									text-decoration: line-through;
									margin-left: 10rpx;
								}
							}

							.cart {
								image {
									width: 40rpx;
									height: 40rpx;
								}
							}
						}
					}
				}
			}
		}
	}
</style>